import { createSlice, type PayloadAction } from "@reduxjs/toolkit";
import type { User } from "../types/user";

export const userSlice = createSlice({
    name:"user",
    initialState:{
        isLogin:false,
        user:{} as User
    },
    reducers:{
        login(state,action:PayloadAction<User>){
            return{
                ...state,
                isLogin: true,
                user: action.payload
            }
        },
        logout(state){
            return{
                ...state,
                user: {} as User,
                isLogin: false,
            }
        },
    }
})

// actionCreater
export const {login,logout} = userSlice.actions

// reducer

export const userReducer = userSlice.reducer